package Optional;
import com.alibaba.fastjson.JSON;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;


/**
 * @Author MJS
 * @Date 2021/8/6 21:20
 * @Description
 */
public class TestOptional {

        public static void main(String[] args) {
            String a =null;
            String unknown = Optional.ofNullable(a).orElseThrow(() -> new RuntimeException("unknown"));
            System.out.println(unknown);
        }
    @Test
    public void beforeJava8() {
            //
            List<Student> studentList = new Student().initData();
            for (Student student : studentList) {
                    if(student!=null){
                            if(student.getScope()!=null && student.getScope()>80 && student.getAge()>=18){
                                    System.out.println(student.getName()+"入选了！");
                            }
                    }
            }
    }
    @Test
    public void java8(){

        List<String> studentList = new Student().initData().stream()
                .filter(student -> student.getScope() != null)
                .filter(student -> student.getAge() >= 18)
                .filter(student -> student.getScope() > 80)
                .map(Student::getName)
                .collect(Collectors.toList());
        for (String s : studentList) {
            System.out.println(s+"入选了");
        }

    }


    @Test
    public void logTest(){
        Student student = new Student();
        System.out.println(student.toString());

        System.out.println(JSON.toJSONString(student));
    }

    @Test
    public void arrayTest(){
            List<Integer>list=new ArrayList<>();
            list.add(1);
            list.add(2);
            list.add(3);
        System.out.println(list);
    }

}
